home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / C++ Related / THooks / Hooks.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-14  |  1.4 KB  |  72 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Hooks.h
  3.  
  4.     Contains:    Hooking into the Mac OS by intercepting traps
  5.                 Creating a Hook object automatically installs the
  6.                 hooks.  Deleting a hook object automaticly disables
  7.                 the hooks, but if somebody else has patched one of the
  8.                 same traps in the mean-time, our hook is left in the
  9.                 system heap.  This is a minor core leak, but much better
  10.                 than crashing the next time the trap is called.
  11.  
  12.     Written by:    Jack Palevich, [Original idea and C implementation by Jay Fenton]
  13.  
  14.     Copyright:    © 1989 by Apple Computer, Inc., all rights reserved.
  15.  
  16.     Change History:
  17.  
  18.         10/15/89    JHP        objectified today
  19.  
  20.     To Do:
  21. */
  22.  
  23. #ifndef __HOOKS__
  24. #define __HOOKS__
  25.  
  26. #ifndef __OSUTILS__
  27. #include <OSUtils.h>
  28. #endif
  29.  
  30. struct hookentry;
  31.  
  32. struct THookStackFrame
  33.     {
  34.     short trap;
  35.     long d0;
  36.     long d1;
  37.     long d2;
  38.     long d3;
  39.     long d4;
  40.     long d5;
  41.     long d6;
  42.     long d7;
  43.     void* a0;
  44.     void* a1;
  45.     void* a2;
  46.     void* a3;
  47.     void* a4;
  48.     void* a5;
  49.     void* returnAddress;
  50.     char argBase;
  51.     };
  52.  
  53. class THooks {
  54. public:
  55.     THooks(short numTraps, const short* trapList,
  56.         pascal void (*trapHandler)(short, THookStackFrame*, void* userRefNum),
  57.         void* userRefNum);
  58.     ~THooks();
  59. private:
  60.     short fNumHooks;
  61.     hookentry* fHooks;
  62. };
  63.  
  64. // Useful for SetTrapAddress and GetTrapAddress
  65.  
  66. inline void TrapToTypeAndNum(short trap, TrapType& trapType, short& trapNum)
  67.     {
  68.     trapType = ( trap >> 11 ) & 1;
  69.     trapNum = trap & ( ( trapType ) ? 0x3ff : 0xff );
  70.     }
  71.  
  72. #endif